<script>
	// import {
	// 	EventBus
	// } from '@/utils/eventBus.js';
	export default {
		onLaunch: function() {
			console.log('App Launch')

			// #ifdef APP-PLUS
			plus.screen.lockOrientation('portrait-primary'); // 设置为竖屏
			plus.device.setWakelock(true);
			// #endif

			const systemInfo = uni.getSystemInfoSync();
			const isTablet = /iPad|Nexus|Q101|Tablet/i.test(systemInfo.model);
			const deviceType = systemInfo.deviceType
			const windowWidth = systemInfo.windowWidth;
			const windowHeight = systemInfo.windowHeight;
			uni.setStorageSync('deviceType', isTablet || deviceType == 'pad' ? 'pad' : 'phone')
			uni.setStorageSync('networkStatus', true)
		},
		created() {

		},
		onShow: function() {
			var that = this;
			// uni.hideTabBar()
			console.log('App Show')
			uni.setStorageSync('appEnterBackground', false)
			that.startListeningToNetworkStatus();
		},
		onHide: function() {
			var that = this;
			console.log('App Hide')
			uni.setStorageSync('appEnterBackground', true)
			that.stopListeningToNetworkStatus();
		},
		methods: {
			startListeningToNetworkStatus() {
				uni.onNetworkStatusChange(this.handleNetworkStatusChange);
			},
			stopListeningToNetworkStatus() {
				uni.offNetworkStatusChange(this.handleNetworkStatusChange);
			},
			handleNetworkStatusChange(res) {
				console.log('网络状态变化:', res.isConnected);
				if (res.isConnected) {
					// uni.showLoading({
					// 	title: '网络恢复',
					// 	mask: true,
					// });
					uni.setStorageSync('networkStatus', true)
					setTimeout(function() {
						uni.hideLoading();
					}, 2000)

					// 在需要的时候触发事件
					this.$eventBus.$emit('network_event');

					// 网络连接
					console.log('当前网络类型:', res.networkType);
				} else {
					uni.setStorageSync('networkStatus', false)

					// 网络断开
					// console.log('网络已断开');
					// uni.showLoading({
					// 	title: '网络异常',
					// 	mask: false,
					// });

					// 在需要的时候触发事件
					this.$eventBus.$emit('network_event');
				}
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import url("static/style/global.css");

	// uniapp引用animate.css动画库
	// * {
	// 	--animate-duration: 0.5s;
	// 	--animate-delay: 0.5s;
	// 	--animate-repeat: 1;
	// }

	/* placeholder样式 */
	input::-webkit-input-placeholder {
		/* placeholder颜色 */
		color: #FFFFFF75;
		/* placeholder字体大小 */
		font-size: 16px
	}

	input {
		-webkit-user-select: text !important;
	}

	// 创建房间页面，选择人数的|音量设置 滑块样式
	::v-deep .uni-slider-handle-wrapper {
		height: 14px !important;
		border-radius: 14px !important;
	}

	::v-deep .uni-slider-track {
		border-top-left-radius: 14px;
		border-bottom-left-radius: 14px;
	}

	// 游戏提交按钮样式
	.submitBtn {
		.hexagon {
			width: 86px;
			height: 96px;
			background-color: #ff01af;
			position: relative;
			overflow: hidden;
			margin: 0px auto;
			clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
		}

		.hexagon:before,
		.hexagon:after {
			content: "";
			position: absolute;
			width: 100%;
			height: 100%;
			left: 0%;
			top: 0%;
			background: linear-gradient(45deg, rgba(255, 255, 255, 0.5), transparent, rgba(255, 255, 255, 0.5));
			animation: rotate 2s linear infinite;
		}

		@keyframes rotate {
			0% {
				transform: rotate(0deg);
			}

			100% {
				transform: rotate(360deg);
			}
		}
	}


	.uni-slider-value {
		text-align: center;
		overflow: hidden;
		width: 4ch !important;
	}



	.CanvasBox {
		width: 100%;
		height: 100%;
		position: absolute;
		top: 0px;
		left: 0px;

		display: flex;
		justify-content: center;
		align-items: center;
	}

	.quit-btn {
		width: 100px;
		height: 28px;
		line-height: 28px;
		text-align: center;
		background: linear-gradient(to bottom, #ffd16b, #fff497);
		border-radius: 28px;
		color: #000;
		font-size: 14px;
		margin: 10px auto;
	}

	/* static/global.css */
	.uv-overlay {
		z-index: 888 !important;
	}
</style>